import { Component, OnInit } from '@angular/core';
import {GlobalDataService} from "../service/global-data.service";

@Component({
  selector: 'app-page-b',
  templateUrl: './page-b.component.html',
  styles: [
  ]
})
export class PageBComponent implements OnInit {
  username = ''
  number = 0
  constructor(private globalDataService$:GlobalDataService) { }

  ngOnInit(): void {
    // console.log("页面初值",this.number)
    // console.log(this.globalDataService$.username)
    this.username = this.globalDataService$.username;
    // console.log(this.username)
    this.globalDataService$.globalVar.subscribe((d:any)=>{
      // console.log("接收",d)
      if(JSON.stringify(d) === '[]') return;
      this.username = d.username;
      this.number = d.number || 0
    })
  }
  change(){
    setTimeout(()=>{
      this.globalDataService$.globalVar.next({username:'王五'});
      // console.log("发出更改number",this.number)
      // this.globalDataService$.globalVar.next({number:this.number+1});
    },1000)
  }
}
